package com.restaurantonlineorder.seller.horseman;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.restaurantonlineorder.seller.domain.Order;
import com.restaurantonlineorder.seller.enums.GoodsState;
import com.restaurantonlineorder.seller.service.IOrderService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author 熊宇
 * @date 2022/7/24 20:04
 * @description
 */
@Service
@Slf4j
public class HorsemanOrderTest {

    @Resource
    private IOrderService iOrderService;


    /**
     * 模拟接单
     */
    @SneakyThrows
    public void takeOrders(Long id) {

        LambdaUpdateWrapper<Order> shippedUpdateWrapper = Wrappers.lambdaUpdate(Order.class);
        shippedUpdateWrapper.set(Order::getGoodsState, GoodsState.SHIPPED)
                .eq(Order::getId, id);
        //修改订单状态
        this.iOrderService.update(shippedUpdateWrapper);
        log.info("正在配送");
        //模拟配送
        TimeUnit.SECONDS.sleep(10);


        log.info("配送完成");
        //配送完成
        LambdaUpdateWrapper<Order> arrivedUpdateWrapper = Wrappers.lambdaUpdate(Order.class);
        arrivedUpdateWrapper.set(Order::getGoodsState, GoodsState.ARRIVED)
                .eq(Order::getId, id);
        this.iOrderService.update(arrivedUpdateWrapper);


    }
}
